import koaBody from 'koa-bodyparser'
import session from 'koa-session'


export const addBody  =app =>{
    app.use(koaBody())
}

export const addSession =app=>{
    app.keys =['JG_Wx_Server']
    const CONFIG = {
        key: 'koa:sess',
        maxAge: 86400000,
        overwrite: true,
        signed: true,
        rolling: false
      }

    app.use(session(CONFIG, app))
}


export const checkSession = app=>{
    app.use(async(ctx,next)=>{
        if(!ctx.session.user){
            console.log('存在session')
        }else {
           ctx.redirect('error/error-401')
        }
    })
}